package com.ai.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ai.common.controller.BaseController;
import com.ai.common.model.Result;
import com.ai.mmd.reviewed.dto.QyshclDTO;
import com.ai.mmd.reviewed.dto.YhxxDTO;
import com.ai.service.reviewed.model.QyshclModel;
import com.ai.service.reviewed.model.YhxxModel;
import com.ai.service.reviewed.service.IQyshclService;
import com.ai.service.reviewed.service.IYhxxService;

/**
 * 
 * Class Name : RegisterController<br>
 * 
 * Description : 注册Controller类<br>
 * 
 * @see
 *
 */
@RequestMapping("login")
@Controller("com.ai.controller.RegisterThreeController")
public class RegisterThreeController extends BaseController {

	@Resource(name = "iyhxxService")
	private IYhxxService iyhxxService;
	@Resource(name = "iqyshclService")
	private IQyshclService iqyshclService;
	@Value("${mainDomain}")
	private String mainDomain;

	/**
	 * Description ：注册引导
	 * @throws Exception 
	 */
	@RequestMapping("/registerthree")
	public String registerindex(@RequestParam(required = true) String userid) throws Exception {
		Result result = new Result();
		result.addAttribute("userid", userid);
		result.rendering();
		
		return "/front/frontgoods/registerthree";
	}
	
	@RequestMapping(value ="/register/three", method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> rgthree(@RequestParam(required = true) String userid)throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();
		
		List<QyshclModel> yhxxModelList = iqyshclService.getList(new QyshclDTO(userid));
		if (yhxxModelList.size()>0) {
			map.put("message", -1);
			return map;
		}
		
		String yyzzfilename = request.getParameter("yyzzfilename");
		String zzjgfilename = request.getParameter("zzjgfilename");
		String swdjfilename = request.getParameter("swdjfilename");
		String qyzzfilename = request.getParameter("qyzzfilename");
		String wtzmfilename = request.getParameter("wtzmfilename");
		String zjlx = request.getParameter("zjlx");
		String szhyfilename = request.getParameter("szhyfilename");
	    
		iyhxxService.insertshcl(userid, yyzzfilename, zzjgfilename, swdjfilename, qyzzfilename, wtzmfilename,zjlx,szhyfilename);
		
		
	
		map.put("message", 1);
		return map;
	}
	
	
	/**
	 * Description ：注册提交
	 * @throws Exception 
	 */
	/* @RequestMapping(value ="/registerconfig", method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> registerconfig(Dlxx dlxx) throws Exception {
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		DlxxKey dlxxKey = new DlxxKey();
		dlxxKey.setYhid(dlxx.getYhid());
		Dlxx dlxxByYhid = dlxxService.selectByPrimaryKey(dlxxKey);
		if (dlxxByYhid!=null) {
			map.put("message", "用户名已存在");
			return map;
		}
		
		Dlxx dlxxBySjh = dlxxService.selectByPhone(dlxx);
		if (dlxxBySjh!=null) {
			map.put("message", "手机号已存在");
			return map;
		}
		
		String token = dlxxService.insertSelective(dlxx);
		if (token!=null) {
			map.put("message", 1);
			session.setAttribute("yhid", dlxx.getYhid());
			session.setAttribute("token", token);
		} else {
			map.put("message", -1);
		}
		
		return map;
	}*/
	
	
}
